<?php
/**
 * Created on 30.09.2007 by Nikolai Plath
* @file mod_bindex.php
*
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
$NL = "\n";
global $limit;

#####
# We include configuration.php to get the default language (also)
#
$biConfig->act_language = $mosConfig_lang;
include( dirname (__FILE__) . '/../configuration.php' );
$biConfig->ini_language = $mosConfig_lang;
$mosConfig_lang = $biConfig->act_language;

$bi_base_path = dirname (__FILE__) . '/../components/com_bindex/';

if( ! file_exists( $bi_base_path . 'bindex.class.php') )
{
	echo $NL.'<span style="color:red">Component not found :(</span>';
	return;
}

include_once( $bi_base_path . 'bindex.class.php');
include_once( $bi_base_path . 'bi_config.class.php');
include_once( $bi_base_path . 'bindex.helper.php');
include_once( $bi_base_path . 'bindex.html.php');
include_once( $bi_base_path . 'gmap.class.php' );

#DEBUG
include_once( $bi_base_path . 'debug.php');
include_once( $bi_base_path . 'debuglib_v4.php');

#Language
if (file_exists( $bi_base_path . 'language/'.$mosConfig_lang.'.php' ) )
{ include_once( $bi_base_path . 'language/'.$mosConfig_lang.'.php' );
} else
{ include_once( $bi_base_path . 'language/english.php' );
}

#flip JS
echo $NL.'<script type="text/javascript" src="'.$mosConfig_live_site.'/components/com_bindex/includes/js/flip.js"></script>';

$DBG		= new nikDebug;
$biConfig	= new biConfig;
$HTML		= new HTML_BIndex;
$DBG->active = $biConfig->DEBUG;
$GMap = new gmap($biConfig);
$biConfig->templatePath		= 'components/com_bindex/templates/';
//$DBG->out($DBG);
//global $DBG;
global $option, $task;

#We try to get itemid from component
$Itemid = $biConfig->getMyItemID();

$id_bereich	= intval( mosGetParam( $_REQUEST, 'id_bereich', 0) );
$id_stadt	= intval( mosGetParam( $_REQUEST, 'id_stadt', 0) );
$gmap		= intval( mosGetParam( $_REQUEST, 'gmap', 0) );
if( $option != 'com_bindex')
{ 
	?>
	<link href="<?php echo $mosConfig_live_site;?>/components/com_bindex/bindex.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" media="all" href="<?php echo $mosConfig_live_site.'/'.$biConfig->templatePath.'app/'.$biConfig->templateApp.'.css'; ?>" />
	
	<?php
} //if
$intro 	= $params->get( 'intro' );

#Bereiche einlesen
$bereiche = getBereiche();

$link_base 		= 'index.php?option=com_bindex&amp;Itemid='.$Itemid;
$link_search 	= $link_base;
$link_base 		.= ( $limit ) ? '&amp;limit='.$limit : '';
$link_go 		= $link_base;
$link_go 		.= ( $task == 'map' ) ? '&amp;task=map' : '&amp;task=bindex';

if( $id_bereich 	> 0 ) $link_base .= '&amp;id_bereich='.$id_bereich;
if( $id_stadt 		> 0 ) $link_base .= '&amp;id_stadt='.$id_stadt;
//$link_base_ajax = 'index2.php?'.$link_base;
//$link_base = 'index.php'.$link_base;

#check if we should "unflip" ;)
if( ($id_stadt==0) && ($id_bereich==0))
{
	#STOP all flipping
	echo $NL.'<script type="text/javascript">flip_stop();</script>';
} //if

$c = $intro;
echo $c;
#$link_ajax_base = "callAHAH('".$link_base."&amp;task=bindex"."', 'bi_ajax_div', 'aaa', 'bbb')";
#$link_ajax_map = "callAHAH('".$link_base."&amp;task=map"."', 'bi_ajax_div', 'aaa', 'bbb')";
echo $NL.'<div align="center">';
		$HTML->_menuStart();//<--START
		$HTML->_menuButton( $link_base, 'bindex', 'home.png', BI_TITEL, FALSE, FALSE, $biConfig); 
		$HTML->_menuButton( $link_base, 'map', 'map.png', BI_MAP, FALSE, FALSE, $biConfig );
		$HTML->_menuEnd();//<--END
echo $NL.'</div>';

# draw home link
echo $NL.'<a href="'.$link_go.'" class="bindex_menu_home"><img src="components/com_bindex/images/home.png" alt="home" border="0" />&nbsp;'.BI_TITEL.'</a>';

$div_count_top = 0;
$div_count_inner = 0;

foreach( $bereiche as $bereich )
{
	$name = getValueBereich( $bereich->id, $mosConfig_lang );
	$selected = ( $id_bereich == $bereich->id ) ? '_selected' : '';
	$link_bereich = $link_go.'&amp;id_bereich='.$bereich->id;
	echo $NL.'<a href="'.$link_go.'&amp;id_bereich='.$bereich->id.'" class="bindex_menu_top'.$selected.'" onclick="setze_keks(\'aktivflip\', \'flipmich'.$div_count_top.'\');">';
	$GMap->_drawGIconBereich( $bereich->id );
	echo( $name ) ? $name : getValueBereich( $bereich->id, $biConfig->ini_language );
	echo $NL.'</a>';
	echo $NL.'<div class="flipbox" id="flipmich'.$div_count_top.'">';
	echo $NL."
<script type=\"text/javascript\">
<!--
flip_visibility('flipmich" . $div_count_top . "', 'none');
// -->
</script>"; 

	#Staedte einlesen
	$staedte = getStaedteFromBereichID($bereich->id);

	foreach( $staedte as $stadt )
	{
		$name = getValueStadtOrDefault( $stadt->id, $mosConfig_lang );
		if( trim( $name ) != '' )//fix to prevent wrong empty items..
		{
			$selected = ( $id_stadt == $stadt->id ) ? '_selected' : '';
			echo $NL.'<a href="'.$link_go.'&amp;id_stadt='.$stadt->id.'" class="bindex_menu'.$selected.'">';
			echo $name;
			echo '</a>';
		} //if
	} //foreach

	echo $NL.'</div>';
	$div_count_top++;
} //foreach

echo $NL.'<script type="text/javascript">flip_check();</script>';

$HTML->_menuStart();//<--START
$HTML->_menuButton( $link_search, 'search', 'search.png', BI_SEARCH );
$HTML->_menuEnd();//<--END

?>